package com.mxsoft;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

public class LogbackRule {

    private static org.slf4j.Logger log = LoggerFactory.getLogger(LogbackRule.class);

    public static void main(String[] args) {
        // 获取logger实例，
        Logger logger = (Logger) LoggerFactory.getLogger("com.mxsoft");

        logger.setLevel(Level.INFO);

        logger.warn("Low fuel level.");

        logger.debug("Starting search for nearest gas station.");

        //从logger继承level等级
        org.slf4j.Logger barlogger = LoggerFactory.getLogger("com.mxsoft.LogbackRule");

        barlogger.info("Located nearest gas station.");

        barlogger.debug("Exiting gas station search");

        new LogbackRule().multiThread();
    }

    public void multiThread() {
        Object obj = new Object();

        new Thread(() -> {
            for (int i = 0; i < 5; i ++) {
                synchronized (obj) {
                    obj.notifyAll();
                    log.info("this is thread-1");
                    if (i < 4) {
                        try {
                            obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            System.out.println("thread-1 run over");
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 5; i ++) {
                synchronized (obj) {
                    log.info("this is thread-2");
                    obj.notifyAll();

                    if (i < 4) {
                        try {
                            obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            System.out.println("thread-2 run over");
        }).start();
    }
}
